package bishi.youzan;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/11 14:36
 */
public class one {
    public static void main(String[] args) {
        one o = new one();
        System.out.println(o.numDecodings("625714527"));
    }

    public int numDecodings(String s) {
        // write code here
        //不合法退出
        if (s == null || s.length() == 0 || s.charAt(0) == '0') return 0;
        char[] chars = s.toCharArray();
        for (int i = 1; i < chars.length; i++) {
            if (chars[i] == '0' && chars[i - 1] == '0') return 0;
        }

        int[] nums = new int[s.length()+1];
        nums[0] = 1;
        nums[1] = 1;
        for (int i = 2; i < s.length(); i++) {
            if (chars[i-1]!='0'){
                nums[i] = nums[i-1];
            }
            int now = (chars[i-2]-'0')*10+chars[i-1];
            if (now>=10&&now<=26){
                nums[i] += nums[i-2];
            }
        }
        return nums[chars.length-1];
    }
}
